package com.mak001.lite.multiSkill.GUI.Tabs;

import java.awt.Dimension;
import java.awt.Insets;
import java.awt.Rectangle;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

import javax.swing.DefaultComboBoxModel;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingConstants;

import com.rsbuddy.script.wrappers.Area;
import com.rsbuddy.script.wrappers.Tile;

public class FisherTab extends JPanel {
	private static final long serialVersionUID = 1L;

	private JTextField textField13;
	private JComboBox fishDropDown;
	private JTextField textField17;
	private JComboBox textField18;
	private JCheckBox pf;

	String[] fish = { "crayfish", "shrimp/anchovy", "sardine/herring", "pike",
			"trout/salmon", "tuna/swordfish", "lobster" };
	String[] places = { "n lumbridge", "lumbridge church" };

	public FisherTab() {
		textField13 = new JTextField();
		fishDropDown = new JComboBox();
		textField17 = new JTextField();
		textField18 = new JComboBox();
		pf = new JCheckBox();
		this.setLayout(null);

		// ---- textField13 ----
		textField13.setText("Fish to Fish");
		textField13.setEditable(false);
		textField13.setHorizontalAlignment(SwingConstants.CENTER);
		this.add(textField13);
		textField13.setBounds(45, 35, 120,
				textField13.getPreferredSize().height);

		// ---- fishDropDown ----
		fishDropDown.setModel(new DefaultComboBoxModel(fish));
		this.add(fishDropDown);
		fishDropDown.setBounds(45, 60, 120,
				fishDropDown.getPreferredSize().height);
		fishDropDown.addItemListener(new ItemListener() {
			@Override
			public void itemStateChanged(ItemEvent e) {
				placeChange(e);
			}
		});

		// ---- textField17 ----
		textField17.setText("Place to Fish");
		textField17.setEditable(false);
		textField17.setHorizontalAlignment(SwingConstants.CENTER);
		this.add(textField17);
		textField17.setBounds(210, 35, 115,
				textField17.getPreferredSize().height);

		// ---- textField18 ----
		textField18.setModel(new DefaultComboBoxModel(places));
		this.add(textField18);
		textField18.setBounds(210, 60, 115,
				textField18.getPreferredSize().height);

		// ---- pf ----
		pf.setText("power fish");
		this.add(pf);
		pf.setBounds(145, 5, 105, pf.getPreferredSize().height);

		{ // compute preferred size
			Dimension preferredSize = new Dimension();
			for (int i = 0; i < this.getComponentCount(); i++) {
				Rectangle bounds = this.getComponent(i).getBounds();
				preferredSize.width = Math.max(bounds.x + bounds.width,
						preferredSize.width);
				preferredSize.height = Math.max(bounds.y + bounds.height,
						preferredSize.height);
			}
			Insets insets = this.getInsets();
			preferredSize.width += insets.right;
			preferredSize.height += insets.bottom;
			this.setMinimumSize(preferredSize);
			this.setPreferredSize(preferredSize);
		}
	}

	protected void placeChange(ItemEvent e) {
		String s = ((JComboBox) e.getSource()).getSelectedItem().toString();
		textField18.setModel(new DefaultComboBoxModel(getFishPlaces(s)));
	}

	private String[] getFishPlaces(String s) {
		if (s.contains("crayfish")) {
			return new String[] { "n lumbridge", "lumbridge church" };
		} else if (s.contains("shrimp")) {
			return new String[] { "draynor", "s lumbridge", "al-kharid",
					"port sarim" };
		} else if (s.contains("sardine")) {
			return new String[] { "draynor", "s lumbridge", "al-kharid",
					"port sarim" };
		} else if (s.contains("pike")) {
			return new String[] { "barbarian village", "lumbridge cows" };
		} else if (s.contains("trout")) {
			return new String[] { "barbarian village", "lumbridge cows" };
		} else if (s.contains("tuna")) {
			return new String[] { "karamja" };
		} else { // lobs
			return new String[] { "karamja" };
		}
	}

	public int[] getGear() {
		String s = fishDropDown.getSelectedItem().toString();
		if (s.contains("crayfish")) {
			return new int[] { 13431 };
		} else if (s.contains("shrimp")) {
			return new int[] { 303 };
		} else if (s.contains("sardine")) {
			return new int[] { 313, 307 };
		} else if (s.contains("pike")) {
			return new int[] { 313, 307 };
		} else if (s.contains("trout")) {
			return new int[] { 314, 309 };
		} else if (s.contains("tuna")) {
			return new int[] { 311 };
		} else { // lobs
			return new int[] { 301 };
		}
	}

	public int[] getFishingSpots() {
		String s = fishDropDown.getSelectedItem().toString();
		if (s.contains("crayfish")) {
			return new int[] { 6267, 6996 };
		} else if (s.contains("shrimp/anchovy")
				|| s.contains("sardine/herring")) {
			return new int[] { 325, 327, 330, 4908 };
		} else if (s.contains("pike") || s.contains("trout/salmon")) {
			return new int[] { 328, 329, };
		} else {// tuna, swordfish, lobster
			return new int[] { 324 };
		}
	}

	public Area getFishingArea() {
		String s = textField18.getSelectedItem().toString();
		if (s.contains("n lumbridge")) {
			return new Area(new Tile(3162, 3263), new Tile(3181, 3278));
		} else if (s.contains("lumbridge church")) {
			return new Area(new Tile(3254, 3197), new Tile(3259, 3219));
		} else if (s.contains("draynor")) {
			return new Area(new Tile(3070, 3220), new Tile(3092, 3236));
		} else if (s.contains("s lumbridge")) {
			return new Area(new Tile(3237, 3143), new Tile(3247, 3163));
		} else if (s.contains("al-kharid")) {
			return new Area(new Tile(3257, 3136), new Tile(3280, 3155));
		} else if (s.contains("port sarim")) {
			return new Area(new Tile(2980, 3140), new Tile(3000, 3194));
		} else if (s.contains("barbarian village")) {
			return new Area(new Tile(3097, 3414), new Tile(3114, 3439));
		} else if (s.contains("lumbridge cows")) {
			return new Area(new Tile(3235, 3234), new Tile(3248, 3259));
		} else {// karamja
			return new Area(new Tile(2917, 3171), new Tile(2929, 3192));
		}
	}

	public String getInteract() {
		String s = fishDropDown.getSelectedItem().toString();
		if (s.contains("crayfish")) {
			return new String("Cage");
		} else if (s.contains("shrimp")) {
			return new String("Net");
		} else if (s.contains("sardine")) {
			return new String("Bait");
		} else if (s.contains("pike")) {
			return new String("Bait");
		} else if (s.contains("trout")) {
			return new String("Lure");
		} else if (s.contains("tuna")) {
			return new String("Harpoon");
		} else { // lobs
			return new String("Cage");
		}
	}

	public boolean getDrop() {
		return pf.isSelected();
	}

	public String getFishName() {
		return fishDropDown.getSelectedItem().toString();
	}

	public boolean getStiles() {
		String s = textField18.getSelectedItem().toString();
		if (s.contains("karamja")) {
			return true;
		}
		return false;
	}

}
